package utils

import "github.com/golang-jwt/jwt/v5"

var JwtKeys = []byte("i18n_template_jwt_keys")

type BuildEncryptJwt struct {
	Username string `json:"username"`
	ID       uint   `json:"id"`
	jwt.RegisteredClaims
}

func GenerateEncryptJwt(username string, id uint) (string, error) {
	generate := jwt.NewWithClaims(jwt.SigningMethodHS256, BuildEncryptJwt{
		username,
		id,
		jwt.RegisteredClaims{
			Issuer:    "i18n_template",
			Subject:   "i18n",
			Audience:  []string{"lysimportant"},
			ExpiresAt: nil,
			NotBefore: nil,
			IssuedAt:  nil,
			ID:        "1",
		},
	})
	signedString, err := generate.SignedString(JwtKeys)
	if err != nil {
		return "", err
	}
	return signedString, err
}

func ParseEncryptJwt(token string) (*jwt.Token, error) {
	claims, err := jwt.ParseWithClaims(token, &BuildEncryptJwt{}, func(token *jwt.Token) (interface{}, error) {
		return JwtKeys, nil
	})
	if err != nil {
		return claims, err
	}

	return claims, nil
}
